<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>身份委托管理</title>

<script src="${ctx}/static/selectWin/userSelector.js"
	type="text/javascript"></script>
<script type="text/javascript">
	var $grid, $grid2, $grid3, $userSelector;
	$(function() {
		$userSelector = $("#userId").comboselector(userSelectOpts);
		var config = {
			method : "get",
			url : "${ctx}/basic/runAsConfig/dataGrid",
			idField : 'id',
			remoteSort : true,
			multiSort : true,
			rownumbers : true,
			fit : true,
			toolbar : '#tt1',
			pagination : true,
			pageList : [ 10, 20, 30, 40, 50, 100 ],
			columns : [ [ {
				field : 'ck',
				checkbox : true
			}, {
				field : 'fromUser',
				title : '委托人',
				sortable : true,
				formatter : function(value, row, index) {
					return value ? value.trueName : "";
				}
			}, {
				field : 'toUser',
				title : '被委托人',
				sortable : true,
				formatter : function(value, row, index) {
					return value ? value.trueName : "";
				}
			}, {
				field : 'inUse',
				title : '是否有效',
				formatter : function(value, row, index) {
					return value == 1 ? "是" : "否";
				}
			}, {
				field : 'remark',
				title : '备注',
				sortable : true
			} ] ],
			enableHeaderClickMenu : true, //此属性开启表头列名称右侧那个箭头形状的鼠标左键点击菜单
			enableHeaderContextMenu : true, //此属性开启表头列名称右键点击菜单
			enableRowContextMenu : false
		};
		$grid = $("#grid").datagrid(config);
		$grid2 = $("#grid2").datagrid($.extend(config, {
			url : "${ctx}/basic/runAsConfig/dataGrid_history",
			toolbar : '#tt2'
		}));
		$grid3 = $("#grid3").datagrid($.extend(config, {
			url : "${ctx}/basic/runAsConfig/dataGrid_granted",
			toolbar : '#tt3'
		}));

		$("#add").click(function() {
			$("#fm").form("clear");
			$('#fm').form('load', {
				enable : 1
			});

			$("#dlg").dialog("open").dialog("setTitle", "新增身份委托");
		});
		$("#delete").click(function() {
			var rowData = $grid.datagrid("getSelected");
			if (rowData == null) {
				$.messager.show({
					msg : "您未选中行，无法取消",
					icon : "warning",
					position : "bottomRight"
				});
			} else {
				$.messager.confirm("您确定要进行该操作？", function(c) {
					if (c) {
						$.get("${ctx}/basic/runAsConfig/delete/" + rowData.id, function(result) {
							$.messager.show({
								msg : result.msg,
								icon : "info",
								position : "bottomRight"
							});
							if (result.success) {
								$grid.datagrid("deleteRow", rowData);
								$grid2.datagrid("load");
							}
						}, 'json');
					}
				});
			}
		});
		$("#search").click(function() {
			$grid.datagrid('load', $("#tt1").form("getData"));
		});
		$("#search2").click(function() {
			$grid2.datagrid('load', $("#tt2").form("getData"));
		});
		$("#search3").click(function() {
			$grid3.datagrid('load', $("#tt3").form("getData"));
		});
	});
	function fn_save() {
		$("#fm").form("submit", {
			url : "${ctx}/basic/runAsConfig/update",
			success : function(data) {
				$grid.datagrid("load");
				$.messager.show({
					msg : data.msg,
					icon : "info",
					position : "bottomRight"
				});
				$("#dlg").dialog('close');
			}
		});
	}
</script>
</head>

<body>
	<div data-options="region:'center',fit:true,border:false">
		<div class="easyui-tabs" data-options="fit:true,border:false">
			<div title="我的身份委托" data-options="refreshable: false">
				<table id="grid">
				</table>
				<div id="tt1" class="row">
					<div class="col-md-4">
						<form class="form-grid-search form-inline">
							<div class="form-group">
								<input name="search_LIKE_fromUser.trueName" type="text" class="form-control" placeholder="身份委托名称" />
							</div>
							<button type="button" id="search" class="btn btn-primary">
								<span class="glyphicon glyphicon-search"></span> 查询
							</button>
						</form>
					</div>
					<div class="col-md-8">
						<button id="add" type="button" class="btn btn-primary">
							<span class="glyphicon glyphicon-plus"></span> 新增
						</button>
						<button id="delete" type="button" class="btn btn-danger">
							<span class="glyphicon glyphicon-minus"></span> 删除
						</button>
					</div>
				</div>
				<div id="dlg" class="easyui-dialog"
					style="width: 350px; height: 230px; padding: 10px 20px"
					data-options="resizable:true,modal:true, buttons:'#dlg-btn',closed:true">
					<form id="fm" method="post">
						<input type="hidden" name="id" />
						<table id="tbl">
							<tr>
								<td><label>被委托人:</label></td>
								<td><input id="userId" name="userId"
									class="easyui-validatebox"></td>
							</tr>
							<tr>
								<td><label>备注:</label></td>
								<td><input name="remark" class="easyui-textbox"
									data-options="multiline:true,width:185,height:60"></td>
							</tr>
						</table>

					</form>
				</div>
			</div>
			<div title="我的身份委托历史" data-options="refreshable: false">
				<table id="grid2">
				</table>
				<div id="tt2" class="row">
					<div class="col-md-4">
						<form class="form-grid-search form-inline">
							<div class="form-group">
								<input name="search_LIKE_fromUser.trueName" type="text" class="form-control" placeholder="身份委托名称" />
							</div>
							<button type="button" id="search2" class="btn btn-primary">
								<span class="glyphicon glyphicon-search"></span> 查询
							</button>
						</form>
					</div>
				</div>
			</div>
			<div title="我收到的身份委托" data-options="refreshable: false">
				<table id="grid3">
				</table>
				<div id="tt3" class="row">
					<div class="col-md-4">
						<form class="form-grid-search form-inline">
							<div class="form-group">
								<input name="search_LIKE_fromUser.trueName" type="text" class="form-control" placeholder="身份委托名称" />
							</div>
							<button type="button" id="search3" class="btn btn-primary">
								<span class="glyphicon glyphicon-search"></span> 查询
							</button>
						</form>
					</div>
				</div>
			</div>
		</div>
		<div id="dlg-btn">
			<button id="save" type="button" class="btn btn-primary"
				onclick="fn_save();">
				<span class="glyphicon glyphicon-ok"></span> 保存
			</button>
			<button id="close" type="button" class="btn btn-primary"
				onclick="$('#dlg').dialog('close');">
				<span class="glyphicon glyphicon-remove"></span> 取消
			</button>
		</div>
	</div>
</body>
</html>
